package com.example.demo.service;

import com.example.demo.entity.CustomUser;
import com.example.demo.entity.ImgDetail;
import com.example.demo.entity.ImgMessage;
import com.example.demo.mapper.ImgDetailMapper;
import com.example.demo.mapper.ImgMapper;
import com.example.demo.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ImgService {
    @Autowired
    ImgMapper imgMapper;

    @Autowired
    UserMapper userMapper;

    @Autowired
    ImgDetailMapper imgDetailMapper;

    public void imgs(String a, String b, String c) {
        imgMapper.insertImg(a, b, c,"体育视频");
    }

    public void getimguserid(String username) {
        imgMapper.getuserimgid(username);
    }

    public List<ImgMessage> getqian3() {
        return imgMapper.getqian3();
    }

    //获取全部图片
    public List<ImgMessage> getqb() {
        for (int i = 0; i < imgMapper.getqb().size(); i++) {
            userMapper.getp(imgMapper.getqb().get(i).getImgid());
            List<CustomUser> getp = userMapper.getp(imgMapper.getqb().get(i).getImgid());
            imgMapper.upshuju(getp.get(0).getName(), imgMapper.getqb().get(i).getImgid());
        }
        return imgMapper.getqb();
    }

    //获取全部图片分页
    public List<ImgMessage> getqbfenye(int currentpage, int pagesize) {
        int temp = 0;
        int i = (temp + currentpage - 1) * pagesize;
        return imgMapper.getpicfenye(i, pagesize);
    }






    public List<ImgMessage> getImgs() {
        List<ImgMessage> imgMessages = imgMapper.returnImg();
        for (int i = 0; i < imgMessages.size(); i++) {
            List<ImgDetail> getid = imgDetailMapper.getid(imgMessages.get(i).getId());
            imgMapper.updata(imgMessages.get(i).getId(), getid.size());
        }
        return imgMapper.returnImg();
    }

    public List<ImgMessage> getvideoall() {
       return imgMapper.returnImg();
    }

    public String deletevideoall(String id) {
        imgMapper.sc_video(id);
        return "删除成功";
    }

}
